package com.shg.jpa.helloworld;

import javax.persistence.*;
import java.util.Date;

@NamedQuery(name = "testNamedQuery",query = "SELECT c FROM Customer c WHERE c.id = ?")
@Table(name = "jpa_customers")
@Entity
public class Customer {

    // 采用strategy = GenerationType.TABLE策略来生成主键
    //@Id
    //@Column(name = "id")
    //@TableGenerator(name = "ID_GENERATOR",
    //        table = "JPA_ID_GENERATORS",
    //        pkColumnName = "PK_NAME",
    //        pkColumnValue = "CUSTOMER_ID",
    //        valueColumnName = "PK_VALUE",
    //        allocationSize = 1)
    //@GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_GENERATOR")

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Integer id;

    @Column(name = "last_name", length = 50, nullable = false)
    private String lastName;

    @Basic
    private String email;

    @Basic
    private int age;

    @Column(name = "create_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    @Basic
    @Temporal(TemporalType.DATE)
    private Date birth;

    public Customer() {
    }

    public Customer(String lastName, int age) {
        this.lastName = lastName;
        this.age = age;
    }

    public Customer(String lastName, String email, int age, Date createTime, Date birth) {
        this(null, lastName, email, age, createTime, birth);
    }

    public Customer(Integer id, String lastName, String email, int age, Date createTime, Date birth) {
        this.id = id;
        this.lastName = lastName;
        this.email = email;
        this.age = age;
        this.createTime = createTime;
        this.birth = birth;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    @Override
    public String toString() {
        return "Customer{" +
                "id=" + id +
                ", lastName='" + lastName + '\'' +
                ", email='" + email + '\'' +
                ", age=" + age +
                ", createTime=" + createTime +
                ", birth=" + birth +
                '}';
    }

    @Transient
    public String getInfo() {
        return "lastName:" + lastName + ",age:" + age;
    }

}
